package com.lwy.qiuchao.integration.service.impl;

import com.lwy.qiuchao.integration.vo.AlltimeVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lwy.common.utils.PageUtils;
import com.lwy.common.utils.Query;

import com.lwy.qiuchao.integration.dao.AllDurationDao;
import com.lwy.qiuchao.integration.entity.AllDurationEntity;
import com.lwy.qiuchao.integration.service.AllDurationService;


@Service("allDurationService")
public class AllDurationServiceImpl extends ServiceImpl<AllDurationDao, AllDurationEntity> implements AllDurationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AllDurationEntity> page = this.page(
                new Query<AllDurationEntity>().getPage(params),
                new QueryWrapper<AllDurationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void updateTime(Long memberId, Long fieldId, Long alltime) {
        baseMapper.updateTime(memberId,fieldId,alltime);
    }

    @Override
    public List<AlltimeVo> getTimelistBymid(Map<String, Object> params) {
        String memberIdStr = (String) params.get("memberId");
        Long memberId = new Long(memberIdStr);
        List<AllDurationEntity> entities = baseMapper.selectList(new QueryWrapper<AllDurationEntity>().eq("member_id", memberId));
        List<AlltimeVo> alltimeVos = entities.stream().map(item -> {
            AlltimeVo vo = new AlltimeVo();
            BeanUtils.copyProperties(item, vo);
            return vo;
        }).collect(Collectors.toList());
        return alltimeVos;
    }

}